
// Media_PlayerDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include "dshow.h"
#include "d3d9.h"
#include <vmr9.h>


#pragma comment(lib,"Strmiids.lib")
#define VOLUME_FULL 0L
#define VOLUME_SILENCE -10000L
#define MAX_SIZE 256
#define MY_TIMEREVENT 9991
#define WM_GRAPHNOTIFY  WM_APP + 1
// CMedia_PlayerDlg dialog
class CMedia_PlayerDlg : public CDialog
{
	//DECLARE_EASYSIZE
// Construction
public:
	CMedia_PlayerDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_MEDIA_PLAYER_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
private:
	CMenu m_Menu;
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	CStatic m_stcPlaying;
	CSliderCtrl m_SliderTimeLife;
	CStatic m_stcTimePlay;
	CStatic m_stcTimeTotal;
	CButton m_btnPlay;
	CButton m_btnStop;
	CSliderCtrl m_SliderVolume;
	
	CString m_strPathFile;
	CString m_strNameFile;
    char szFileName[MAX_SIZE];

	bool isPlaying;
	bool m_bInit;
	long totalDuration;
	long lVolume;
	long timeElapsed;
	float step;

	HWND hOwner;
	REFERENCE_TIME m_refTimeNow;
	REFERENCE_TIME m_refTimePlay;
	LONGLONG lTotalDuration;
	
	IGraphBuilder          *pGB;
	IMediaControl		   *pMC;
	IMediaSeeking          *pMS;
	IMediaEventEx          *pME;
	IBasicAudio            *pAudio;
	IVMRWindowlessControl9 *pWc;

	RECT rcSource, rcDest;
	HWND hwnd;

	HRESULT InitWindowlessVMR(HWND hwndApp, IGraphBuilder *pGraph, IVMRWindowlessControl9 **ppWc);
	void Initialize(HWND owner);
	int StartPlayingFile();
	int PlayPauseMedia();
	int StopMedia();
	int DoTimeStuff();
    int ReleaseVal();
	int HanldeEventFromGraph();
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	afx_msg void OnBnClickedBtnPlay();
	afx_msg void OnBnClickedBtnStop();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg void OnNMReleasedcaptureSldLife(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMReleasedcaptureSldVolume(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnFileOpen();
	afx_msg void OpenFile();
	afx_msg void OnFileClose();
	afx_msg void OnControlPlay();
	afx_msg void OnControlMute();
	afx_msg void OnAbout();
	afx_msg void OnControlStop();
};
